Word = Ext.extend(Ext.app.Module, {
	id: 'word-win',
	htmlEditor: new Ext.form.HtmlEditor,
	init: function(){
		this.launcher = {
			text: 'Futura Word',
			iconCls: 'icon-grid',
			handler: this.createWindow,
			scope: this
		}
	},

	createWindow: function() {
		var desktop = this.app.getDesktop();
		var win = desktop.getWindow('word-win');
		if(!win){
			win = desktop.createWindow({
				id: 'word-win',
				title: 'Futura Word',
				iconCls: 'icon-grid',
				maximizable: true,
				minimizable: true,
				width: 600,
				height: 400,
				layout:'fit',
				items: this.htmlEditor,
				tbar: [
					{ text: 'New', handler: function() { this.htmlEditor.setValue(""); }, scope: this },
					'-',
					{ text: 'Open', handler: this.openDialog, scope: this },
					{ text: 'Save', handler: this.saveDialog, scope: this }
				]
			});
		}
		win.show();
	},

	openDialog: function() {
		var self = this;
		var dialog = new OpenDialog(function(filename) {
			self.loadD(filename);
		});
		dialog.show();
    },
	
	saveDialog: function() {
		var self = this;
		var dialog = new SaveDialog(function(filename) {
			self.saveD(filename);
		});
		dialog.show();
	},

	loadD: function(file) {
		var self = this;
		Ext.Ajax.request({
			url: '../php/read_file.php',
			params: { filename: file },
			success: function(response) {
				self.htmlEditor.setValue(response.responseText);
			}
		});
	},
	
	saveD: function(file) {
		var self = this;
		Ext.Ajax.request({
			url: '../php/save_file.php',
			params: { filename: file, content: self.htmlEditor.getValue() },
			success: function(response) {
				Ext.Msg.alert("Status", response.responseText);
			}
		});
	}
});
